package com.xbongbong.paas.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.model.PaasEsModel;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.service.ProModelService;
import com.xbongbong.paas.service.dynamic.help.DynamicHelp;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.FormDataUtil;
import com.xbongbong.parent.pojo.AddValidateReturnPojo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.BuinessDefaultErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO;
import com.xbongbong.pro.formdata.pojo.vo.SaveVO;
import com.xbongbong.pro.product.pojo.ProductWithSupplierPojo;
import com.xbongbong.pro.product.pojo.ProductWithWarehousePojo;
import com.xbongbong.pro.product.pojo.StockNotifyPojo;
import com.xbongbong.pro.product.pojo.vo.ChildProductVO;
import com.xbongbong.product.abstracts.AbstractProductAddDataService;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.ProductSubDataEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.model.ProductModel;
import com.xbongbong.saas.model.ProductSubDataModel;
import com.xbongbong.saas.service.ProductService;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;

/**
 *
 * @author 魏荣杰
 * @date 2021/1/4 16:22
 * @since
 * @version
 */
@Service("productFormDataServiceImpl")
public class ProductFormDataServiceImpl extends AbstractProductAddDataService {

    private static final Logger LOG = LoggerFactory.getLogger(ProductFormDataServiceImpl.class);

    @Resource
    private ProductService productService;
    @Resource
    private ProductModel productModel;
    @Resource
    private PaasAppServiceImpl paasAppService;
    @Resource
    private ProModelService proModelService;
    @Resource
    private DynamicHelp dynamicHelp;
    @Resource
    private PaasEsModel paasEsModel;
    @Resource
    private ProductSubDataModel productSubDataModel;

    @Override
    public List<Integer> businessList() {
        return Arrays.asList(XbbRefTypeEnum.PRODUCT.getCode());
    }

    @Override
    public AddValidateReturnPojo analyticalData(FormDataAddDTO formDataAddDTO, ValidateDataDTO validateDataDTO, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        AddValidateReturnPojo addValidateReturnPojo = super.analyticalData(formDataAddDTO, validateDataDTO, explainMap);
        formDataAddDTO.setVisbleDept(validateDataDTO.getVisbleDept());
        formDataAddDTO.setVisbleUser(validateDataDTO.getVisbleUser());
        return addValidateReturnPojo;
    }
    @Override
    public SaveVO save(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, PaasFormEntityExt paasFormEntity, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        Long dataId = 0L;
        String corpid = formDataAddDTO.getCorpid();
        Integer saasMark = formDataAddDTO.getSaasMark();
        Integer businessType = formDataAddDTO.getBusinessType();
        try {
            ChildProductVO childProductVO = null;
            UserVO userVO = getUserName(formDataAddDTO, paasFormDataEntity);
            Integer noApprovalRequired = beforeSaveVO.getNoApprovalRequired();
            if (Objects.equals(1, noApprovalRequired)) {
                // 深拷贝出数据
                JSONObject childData = (JSONObject) paasFormDataEntity.getData().clone();
                ProductEntityExt productEntityExt = new ProductEntityExt();
                BeanUtil.copyProperties(paasFormDataEntity, productEntityExt);
                JSONObject dataList = productEntityExt.getData();
                Map<Long, String> supplierNameMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                Map<Long, String> warehouseNameMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                List<StockNotifyPojo> stockNotifyList = productService.getSaveParam(dataList, supplierNameMap, warehouseNameMap);
                productService.formatParentProduct4Save(dataList,corpid, productEntityExt);
                // 父产品部分数据存入关联表，原数据置空
                proModelService.setDefaultData(RedundantTemplateTypeEnum.PRODUCT, dataList);
                if (Objects.isNull(dataList.get(ProductEnum.COST.getAttr()))){
                    dataList.put(ProductEnum.COST.getAttr(),0);
                }
                FormDataUtil.removeSystemData(dataList);
                Object richTextData = removeRichText(dataList);
                productEntityExt.setData(dataList);
                productEntityExt.setCost(dataList.getDouble(ProductEnum.COST.getAttr()));
                productEntityExt.setTotalCost(0D);
                productModel.insert(productEntityExt);

                dataId = productEntityExt.getId();
                // 设置属性用于返回
                setPartialAttributes(dataId, productEntityExt.getSubFormData(), productEntityExt.getData(), productEntityExt.getAddTime(),
                        productEntityExt.getUpdateTime(), paasFormDataEntity, beforeSaveVO);
                // 保存子产品
                // 是否开启进销存
                Boolean isJxcUse = paasAppService.validateAppEnable(null, XbbRefTypeEnum.JXC.getAlias(), SaasMarkEnum.SAAS.getCode(), corpid);
                // 子产品部分数据存入关联表，原数据置空
                setProductDefaultData(childData);
                FormDataUtil.removeSystemData(childData);
                paasFormDataEntity.setData(childData);
                childData.put(ProductEnum.WAREHOUSE.getAttr(),dataList.getJSONArray(ProductEnum.WAREHOUSE.getAttr()));
                childData.put(ProductEnum.WAREHOUSE_LINK_TEXT.getAttr(),dataList.getJSONArray(ProductEnum.WAREHOUSE_LINK_TEXT.getAttr()));
                childData.put(ProductEnum.SUPPLIER.getAttr(),dataList.getJSONArray(ProductEnum.SUPPLIER.getAttr()));
                childData.put(ProductEnum.SUPPLIER_LINK_TEXT.getAttr(),dataList.getJSONArray(ProductEnum.SUPPLIER_LINK_TEXT.getAttr()));
                FieldAttrEntity costField = formDataAddDTO.getExplainMap().get(ProductEnum.COST.getAttr());
                Integer costAccuracy = Objects.isNull(costField) ? null : costField.getAccuracy();
                childProductVO = productService.saveChildProduct(paasFormDataEntity, isJxcUse, true, costAccuracy);

                // 先保存供应商-产品信息，因为后面子产品的保存要对供应商字段做修改
                if (isJxcUse) {
                    productService.associateWithSupplier(new ProductWithSupplierPojo(corpid, childProductVO, supplierNameMap, dataId));
                    ProductWithWarehousePojo productWithWarehousePojo = new ProductWithWarehousePojo(corpid, childProductVO, warehouseNameMap, dataId, stockNotifyList, false, dataList.getDouble(ProductEnum.COST.getAttr()));
                    BeanUtil.copyProperties(formDataAddDTO, productWithWarehousePojo);
                    if (Objects.nonNull(formDataAddDTO.getSaasNeedRedundantAttrPoJo())) {
                        productWithWarehousePojo.setProductWarehouseSavePojo(beforeSaveVO.getSaasNeedRedundantAttrPojo().getProductWarehouseSavePojo());
                    }
                    productService.associateWithWarehouse(productWithWarehousePojo);
                }
                //文件柜数据保存
                saveFile(formDataAddDTO, paasFormDataEntity, userVO);
                //富文本数据保存
                saveRichText(formDataAddDTO, paasFormDataEntity, richTextData);
            }
            return new SaveVO(noApprovalRequired, paasFormDataEntity, dataId, userVO, childProductVO);
        } catch (XbbException e) {
            LOG.warn(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw e;
        } catch (Exception e) {
            LOG.error(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw new XbbException(BuinessDefaultErrorCodeEnum.API_ERROR_200018);
        }
    }


    @Override
    public void saveRollBack(Long id, String corpid, Integer saasMark, Integer businessType) throws XbbException {
        if (id == null || id == 0 || corpid == null || saasMark == null) {
            return ;
        }
        IndexTypeEnum indexTypeEnum = getIndexTypeEnum(corpid, saasMark, businessType);
        //删除主表es数据
        physicalDeleteFormData(id, corpid, indexTypeEnum);
        BoolQueryBuilder boolQueryBuilder = boolQuery();
        // 回滚子产品
        boolQueryBuilder.filter(termQuery("corpid.keyword", corpid));
        boolQueryBuilder.filter(termQuery("del", DelEnum.NORMAL.getDel()));
        boolQueryBuilder.filter(termQuery(StringConstant.JSON_DATA + StringConstant.POINT + ProductEnum.PARENT_ID.getAttr(), id));
        List<PaasFormDataEntity> dataList = paasEsModel.getDataList(boolQueryBuilder, IndexTypeEnum.IDX_SAAS_PRODUCT, new ArrayList<>(), 1, 10000, PaasFormDataEntity.class, FieldTypeEnum.UPDATETIME.getAlias(), SortOrder.DESC);
        if (CollectionsUtil.isNotEmpty(dataList)) {
            for (PaasFormDataEntity item : dataList) {
                physicalDeleteFormData(item.getDataId(), corpid, indexTypeEnum);
            }
        }
        // 子表单的删除
        List<ProductSubDataEntity> productSubDataEntities = productSubDataModel.getByDataId(id, corpid);
        if (CollectionsUtil.isNotEmpty(productSubDataEntities)) {
            physicalDeleteSubBatch(corpid, productSubDataEntities, IndexTypeEnum.IDX_SAAS_PRODUCT_SUB);
        }
    }

    @Override
    public FormDataAddVO afterSave(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, SaveVO saveVO, PaasFormEntityExt paasFormEntity, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        FormDataAddVO formDataAddVO = new FormDataAddVO();
        Long dataId = saveVO.getDataId();
        String corpid = formDataAddDTO.getCorpid();
        Integer saasMark = formDataAddDTO.getSaasMark();
        Integer businessType = formDataAddDTO.getBusinessType();
        try {
            if (Objects.equals(1, saveVO.getNoApprovalRequired())) {
                SaasFormSaveDTO saasFormSaveDTO = new SaasFormSaveDTO();
                BeanUtil.copyProperties(formDataAddDTO, saasFormSaveDTO);
                packageSaasFormInsertSaveDTO(saasFormSaveDTO, paasFormDataEntity);
                // 将子产品相关数据作为入参
                saasFormSaveDTO.setChildProductVO(saveVO.getChildProductVO());
                saasFormSaveDTO.setSaasNeedRedundantAttrPoJo(beforeSaveVO.getSaasNeedRedundantAttrPojo());
                productService.afterSave(saasFormSaveDTO);

                // log
                afterSaveLog(formDataAddDTO, paasFormEntity, paasFormDataEntity, saveVO, beforeSaveVO);
                // 动态处理
                dynamicHelp.addLinkData(saasFormSaveDTO);
                // api
                apiHook(formDataAddDTO, saveVO, beforeSaveVO);
                // 业务规则
                activeRule(formDataAddDTO, beforeSaveVO, paasFormDataEntity, beforeSaveVO.getPaasFormEntityExt());
                formDataAddVO.setMsg(I18nMessageUtil.getMessage(MessageConstant.FORM_ADD_RETURN_MSG));
                formDataAddVO.setCode(PaasConstant.FORM_ADD_RETURN_CODE);
                formDataAddVO.setDataId(saveVO.getDataId());
                formDataAddVO.setFormDataId(saveVO.getDataId());
            } else {
                formDataAddVO.setMsg(I18nMessageUtil.getMessage(MessageConstant.FORM_ADD_PROCESS_RETURN_MSG));
                formDataAddVO.setCode(PaasConstant.FORM_ADD_PROCESS_RETURN_CODE);
            }
            return formDataAddVO;
        }  catch (XbbException e) {
            LOG.warn(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw e;
        } catch (Exception e) {
            LOG.error(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw new XbbException(BuinessDefaultErrorCodeEnum.API_ERROR_200018);
        }
    }

    @Override
    public void afterSaveLog(FormDataAddDTO formDataAddDTO, PaasFormEntityExt paasFormEntityExt, PaasFormDataEntity newPaasFormDataEntity, SaveVO saveVO, BeforeSaveVO beforeSaveVO) throws XbbException {
        boolean isImport = Objects.equals(1, formDataAddDTO.getIsImport());
        if (isImport) {
            return;
        }
        JSONObject data = newPaasFormDataEntity.getData();
        StringBuilder sb = new StringBuilder();
        String serialNo = FastJsonHelper.getStringOrDefaultFromFormData(data, ProductEnum.PRODUCT_NO.getAttr(), "");
        String name = data.getString(ProductEnum.NAME.getAttr());
        String logName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
        saveLogger(formDataAddDTO, newPaasFormDataEntity, logName, XbbRefTypeEnum.PRODUCT.getName(), OperateModuleTypeEnum.PRODUCT, saveVO, beforeSaveVO);
    }
    /**
     * 设置产品默认值，这些值保存在关联表
     *
     * @param childData
     */
    public void setProductDefaultData(JSONObject childData) {
        if (Objects.isNull(childData.get(ProductEnum.COST.getAttr()))) {
            childData.put(ProductEnum.COST.getAttr(), 0.0);
        }
        if (Objects.isNull(childData.get(ProductEnum.PRICE.getAttr()))) {
            childData.put(ProductEnum.PRICE.getAttr(), 0.0);
        }
        if (Objects.isNull(childData.get(ProductEnum.STOCK.getAttr()))) {
            childData.put(ProductEnum.STOCK.getAttr(), 0.0);
        }
        if (Objects.nonNull(childData.get(ProductEnum.STOCK_NOTIFY.getAttr()))) {
            childData.put(ProductEnum.STOCK_NOTIFY.getAttr(), null);
        }
    }

    @Override
    public void apiHook(FormDataAddDTO formDataAddDTO, SaveVO saveVO, BeforeSaveVO beforeSaveVO) throws XbbException {
        lowCodeExecuteService(formDataAddDTO, saveVO, beforeSaveVO);
    }

    @Override
    public SaveVO saveForWorkflow(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, PaasFormEntityExt paasFormEntity, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        Long dataId = 0L;
        String corpid = formDataAddDTO.getCorpid();
        Integer saasMark = formDataAddDTO.getSaasMark();
        Integer businessType = formDataAddDTO.getBusinessType();
        try {
            ChildProductVO childProductVO = null;
            UserVO userVO = getUserName(formDataAddDTO, paasFormDataEntity);
            Integer noApprovalRequired = beforeSaveVO.getNoApprovalRequired();
            // 深拷贝出数据
            JSONObject childData = (JSONObject) paasFormDataEntity.getData().clone();
            ProductEntityExt productEntityExt = new ProductEntityExt();
            BeanUtil.copyProperties(paasFormDataEntity, productEntityExt);
            JSONObject dataList = productEntityExt.getData();
            Map<Long, String> supplierNameMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            Map<Long, String> warehouseNameMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            List<StockNotifyPojo> stockNotifyList = productService.getSaveParam(dataList, supplierNameMap, warehouseNameMap);
            productService.formatParentProduct4Save(dataList,corpid, productEntityExt);
            // 父产品部分数据存入关联表，原数据置空
            proModelService.setDefaultData(RedundantTemplateTypeEnum.PRODUCT, dataList);
            if (Objects.isNull(dataList.get(ProductEnum.COST.getAttr()))){
                dataList.put(ProductEnum.COST.getAttr(),0);
            }
            boolean enableMultiUnit = Objects.equals(dataList.getIntValue(ProductEnum.ENABLE_MULTI_UNIT.getAttr()), BasicConstant.ONE);
            FormDataUtil.removeSystemData(dataList);
            Object richTextData = removeRichText(dataList);
            productEntityExt.setData(dataList);
            if (enableMultiUnit) {
                childData.put(ProductEnum.PRICE.getAttr(), productEntityExt.getData().get(ProductEnum.PRICE.getAttr()));
                productEntityExt.getData().remove(ProductEnum.PRICE.getAttr());
            }
            productEntityExt.setCost(dataList.getDouble(ProductEnum.COST.getAttr()));
            productEntityExt.setTotalCost(0D);
            productModel.insert(productEntityExt);

            dataId = productEntityExt.getId();
            // 设置属性用于返回
            setPartialAttributes(dataId, productEntityExt.getSubFormData(), productEntityExt.getData(), productEntityExt.getAddTime(),
                    productEntityExt.getUpdateTime(), paasFormDataEntity, beforeSaveVO);
            // 保存子产品
            // 是否开启进销存
            Boolean isJxcUse = paasAppService.validateAppEnable(null, XbbRefTypeEnum.JXC.getAlias(), SaasMarkEnum.SAAS.getCode(), corpid);
            // 子产品部分数据存入关联表，原数据置空
            setProductDefaultData(childData);
            FormDataUtil.removeSystemData(childData);
            paasFormDataEntity.setData(childData);
            childData.put(ProductEnum.WAREHOUSE.getAttr(),dataList.getJSONArray(ProductEnum.WAREHOUSE.getAttr()));
            childData.put(ProductEnum.WAREHOUSE_LINK_TEXT.getAttr(),dataList.getJSONArray(ProductEnum.WAREHOUSE_LINK_TEXT.getAttr()));
            childData.put(ProductEnum.SUPPLIER.getAttr(),dataList.getJSONArray(ProductEnum.SUPPLIER.getAttr()));
            childData.put(ProductEnum.SUPPLIER_LINK_TEXT.getAttr(),dataList.getJSONArray(ProductEnum.SUPPLIER_LINK_TEXT.getAttr()));
            FieldAttrEntity costField = formDataAddDTO.getExplainMap().get(ProductEnum.COST.getAttr());
            Integer costAccuracy = Objects.isNull(costField) ? null : costField.getAccuracy();
            childProductVO = productService.saveChildProduct(paasFormDataEntity, isJxcUse, true, costAccuracy);

            // 先保存供应商-产品信息，因为后面子产品的保存要对供应商字段做修改
            if (isJxcUse) {
                productService.associateWithSupplier(new ProductWithSupplierPojo(corpid, childProductVO, supplierNameMap, dataId));
                ProductWithWarehousePojo productWithWarehousePojo = new ProductWithWarehousePojo(corpid, childProductVO, warehouseNameMap, dataId, stockNotifyList, false, dataList.getDouble(ProductEnum.COST.getAttr()));
                BeanUtil.copyProperties(formDataAddDTO, productWithWarehousePojo);
                if (Objects.nonNull(formDataAddDTO.getSaasNeedRedundantAttrPoJo())) {
                    productWithWarehousePojo.setProductWarehouseSavePojo(beforeSaveVO.getSaasNeedRedundantAttrPojo().getProductWarehouseSavePojo());
                }
                productService.associateWithWarehouse(productWithWarehousePojo);
            }
            //文件柜数据保存
//            saveFile(formDataAddDTO, paasFormDataEntity, userVO);
            //富文本数据保存
            saveRichText(formDataAddDTO, paasFormDataEntity, richTextData);

            return new SaveVO(noApprovalRequired, paasFormDataEntity, dataId, userVO, childProductVO);
        } catch (XbbException e) {
            LOG.warn(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw e;
        } catch (Exception e) {
            LOG.error(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw new XbbException(BuinessDefaultErrorCodeEnum.API_ERROR_200018);
        }
    }

    @Override
    public FormDataAddVO afterSaveForWorkflow(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, SaveVO saveVO, PaasFormEntityExt paasFormEntity, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        FormDataAddVO formDataAddVO = new FormDataAddVO();
        Long dataId = saveVO.getDataId();
        String corpid = formDataAddDTO.getCorpid();
        Integer saasMark = formDataAddDTO.getSaasMark();
        Integer businessType = formDataAddDTO.getBusinessType();
        try {
            SaasFormSaveDTO saasFormSaveDTO = new SaasFormSaveDTO();
            BeanUtil.copyProperties(formDataAddDTO, saasFormSaveDTO);
            packageSaasFormInsertSaveDTO(saasFormSaveDTO, paasFormDataEntity);
            // 将子产品相关数据作为入参
            saasFormSaveDTO.setChildProductVO(saveVO.getChildProductVO());
            saasFormSaveDTO.setSaasNeedRedundantAttrPoJo(beforeSaveVO.getSaasNeedRedundantAttrPojo());
            productService.afterSaveForWorkflow(saasFormSaveDTO);

            // log
//            afterSaveLog(formDataAddDTO, paasFormDataEntity, saveVO, beforeSaveVO);
            // api
//            apiHook(formDataAddDTO, saveVO, beforeSaveVO);
            // 业务规则
//            activeRule(formDataAddDTO, beforeSaveVO, paasFormDataEntity, beforeSaveVO.getPaasFormEntityExt());
            formDataAddVO.setDataId(saveVO.getDataId());
            formDataAddVO.setFormDataId(saveVO.getDataId());
            formDataAddVO.setMsg(I18nMessageUtil.getMessage(MessageConstant.FORM_ADD_RETURN_MSG));
            formDataAddVO.setCode(PaasConstant.FORM_ADD_RETURN_CODE);
            return formDataAddVO;
        }  catch (XbbException e) {
            LOG.warn(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw e;
        } catch (Exception e) {
            LOG.error(BuinessDefaultErrorCodeEnum.API_ERROR_200018.getMsg(),e);
            saveRollBack(dataId, corpid, saasMark, businessType);
            throw new XbbException(BuinessDefaultErrorCodeEnum.API_ERROR_200018);
        }
    }
}
